﻿using System;
using System.Web.Mvc;

namespace mesoBoard.Web.Helpers
{
    public static class UrlHelpers
    {
        public static string PluginContent(this UrlHelper url, string contentPath)
        {
            string pluginFolder = (string)url.RequestContext.HttpContext.Items[HttpContextItemKeys.PluginFolder];

            if(string.IsNullOrWhiteSpace(pluginFolder))
                throw new InvalidOperationException("No plugin folder declared. 'PluginContent' must be called in side a view generated by a plugin controller action");

            return url.Content("~/Plugins/" + pluginFolder + "/" + contentPath);

        }

        public static string AdminContent(this UrlHelper url, string contentPath)
        {
            return url.Content(System.IO.Path.Combine("~/Areas/Admin/Content", contentPath));
        }


        public static string ThemeImage(this UrlHelper url, string imageFileName)
        {
            string themeName = url.RequestContext.HttpContext.Items[HttpContextItemKeys.ThemeFolder].ToString();

            return url.Content("~/Themes/" + themeName + "/Images/" + imageFileName);
        }

        public static string ThemeContent(this UrlHelper url, string themeFolderRelativeContentPath)
        {
            string themeName = url.RequestContext.HttpContext.Items[HttpContextItemKeys.ThemeFolder].ToString();

            themeFolderRelativeContentPath = themeFolderRelativeContentPath.Replace("~/", "");

            return url.Content("~/Themes/" + themeName + "/" + themeFolderRelativeContentPath);
        }
    }
}
